/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Servlets;

import Entities.PcroomlistFacade;
import classes.Seat;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Sarah
 */
@WebServlet(name = "DbServlet", urlPatterns = {"/DbServlet"})
public class DbServlet extends HttpServlet {
    @EJB
    private PcroomlistFacade pcroomlistFacade;

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            ArrayList<Seat> SEAT = new ArrayList<Seat>();
            for (int i = 1; i <= 5; i++) {
                for (int j = 1; j <= 5; j++) {
                    Seat seat = new Seat(j, i, (i-1)*5+j);
                    seat.setIsAvailable(Boolean.TRUE);
                    SEAT.add(seat);
                }
            }

            pcroomlistFacade.addPcroom("VIVALDI PC존", 37.2783, 127.0434, "경기도 수원시 팔달구 우만동 575-1 아록빌딩 5층", "031-212-8959", SEAT);
            SEAT = new ArrayList<Seat>();
            for (int i = 1; i <= 5; i++) {
                for (int j = 1; j <= 5; j++) {
                    Seat seat = new Seat(j, i, (i-1)*5+j);
                    seat.setIsAvailable(Boolean.TRUE);
                    SEAT.add(seat);
                }
            }
            pcroomlistFacade.addPcroom("TOP PC방", 37.2783, 127.0434, "경기도 수원시 영통구 원천동 18-1 아록빌딩", "031-217-5321", SEAT);
            SEAT = new ArrayList<Seat>();
            for (int i = 1; i <= 5; i++) {
                for (int j = 1; j <= 5; j++) {
                    Seat seat = new Seat(j, i, (i-1)*5+j);
                    seat.setIsAvailable(Boolean.TRUE);
                    SEAT.add(seat);
                }
            }
            pcroomlistFacade.addPcroom("자이젠 PC방", 37.2764, 127.0405, "경기도 수원시 팔달구 우만동 96-32 우신빌딩 2층", "031-214-7222", SEAT);

            /* TODO output your page here. You may use following sample code. */
            out.println("<!DOCTYPE html>");
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet DbServlet</title>");            
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet DbServlet at " + request.getContextPath() + "</h1>");
            out.println("</body>");
            out.println("</html>");
        } finally {            
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
